use "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200618/ns20200618.dta"
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200102/ns20200102.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200423/ns20200423.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200611/ns20200611.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200220/ns20200220.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200227/ns20200227.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200409/ns20200409.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200604/ns20200604.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200430/ns20200430.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200116/ns20200116.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200312/ns20200312.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200528/ns20200528.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200521/ns20200521.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200130/ns20200130.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200305/ns20200305.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200507/ns20200507.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200109/ns20200109.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200213/ns20200213.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200416/ns20200416.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200625/ns20200625.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200206/ns20200206.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200402/ns20200402.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200326/ns20200326.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200319/ns20200319.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200514/ns20200514.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace
append using "/Users/sierravaldez/Downloads/Nationscape-Weekly-Materials-DTA-2021Dec/phase_2_v20210301/ns20200123/ns20200123.dta"
save NSmergeddata.dta, replace
use NSmergeddata.dta, replace

gen monthyear = mofd(dofc(start_date))
format monthyear %tm

***need to create attritor variables based on parents
***drop other months and years
drop if inlist(monthyear, tm(2020m1), tm(2020m2))

***this is only for 2020 march - july
gen latino_parent = 0
replace latino_parent = 1 if extra_race_latino_mom == 1 
replace latino_parent = 1 if extra_race_latino_dad == 1

gen two_latino_parents = 0
replace two_latino_parents = 1 if extra_race_latino_mom == 1 & extra_race_latino_dad == 1

***this is only for 2020 march - july
gen white_parent = 0
replace white_parent = 1 if extra_race_white_mom == 1
replace white_parent = 1 if extra_race_white_dad == 1

***this is only for 2020 march - july
gen black_parent = 0
replace black_parent = 1 if extra_race_black_mom == 1
replace black_parent = 1 if extra_race_black_dad == 1

**1465 total
gen attritor = 0
**1 = 0 for hispanic, >1 is hispanic
replace attritor = 1 if hispanic == 1 & latino_parent == 1

**888 white
gen white_attritor = 0
replace white_attritor = 1 if attritor == 1 & race == 1

gen black_attritor = 0
replace black_attritor = 1 if attritor == 1 & race == 2
*388 black attritors

*attritor w two latino parents
gen full_attritor = 0
replace full_attritor = 1 if attritor == 1 & two_latino_parents == 1
**for some reason there is no mixed race attritors?? why 

gen full_attritor_white = 0
replace full_attritor_white = 1 if white_attritor == 1 & two_latino_parents == 1

gen full_attritor_black = 0
replace full_attritor_black = 1 if black_attritor == 1 & two_latino_parents == 1


**test mixed
tab hispanic if extra_race_white_mom == 1 & extra_race_latino_dad == 1

**clean racial resentment scale
recode racial_attitudes_tryhard (1=5) (2=4) (3=3) (4=2) (5=1), gen(rev_racial_attitudes_tryhard)
gen racial_resentment = rev_racial_attitudes_tryhard + racial_attitudes_generations
egen racial_resentment_min = min(racial_resentment)
egen racial_resentment_max = max(racial_resentment)
gen racial_resentment_rescaled = (racial_resentment - racial_resentment_min) / (racial_resentment_max - racial_resentment_min)

**create straight up racism
recode racial_attitudes_marry (1=5) (2=4) (3=3) (4=2) (5=1), gen(rev_racial_attitudes_marry)
gen racial_dating = rev_racial_attitudes_marry + racial_attitudes_date
egen racial_dating_min = min(racial_dating)
egen racial_dating_max = max(racial_dating)
gen racial_dating_rescaled = (racial_dating - racial_dating_min) / (racial_dating_max - racial_dating_min)

**
***model H controls
**svy: probit black_attritor_single_race FIRE_scale_rescaled dominican pid7_rescaled pid7_noanswer i.gender i.year generation faminc_rescaled cit1_rescaled citizen_missing educ_rescaled catholic marstat_rescaled marstatus_missing pct_hisp_zip_rescaled pct_hisp_zip_missing pct_black_zip_rescaled pct_black_zip_missing if race == 2

**recode pid7
egen pid7_min = min(pid7)
egen pid7_max = max(pid7)
gen pid7_rescaled = (pid7 - pid7_min) / (pid7_max - pid7_min)

**recode ideo5
egen ideo5_min = min(ideo5)
egen ideo5_max = max(ideo5)
gen ideo5_rescaled = (ideo5 - ideo5_min) / (ideo5_max - ideo5_min)

**recode year
egen monthyear_min = min(monthyear)
egen monthyear_max = max(monthyear)
gen monthyear_rescaled = (monthyear - monthyear_min) / (monthyear_max - monthyear_min)

**age
**make a generations variable
gen generation = .
**GI
replace generation = 1 if age > 94
**silent
replace generation = 2 if age > 76 & age < 95
**baby boom
replace generation = 3 if age > 57 & age < 77
**generation x
replace generation = 4 if age > 41 & age < 58
**millennial
replace generation = 5 if age > 25 & age < 43
**gen z
replace generation = 6 if age < 26

**recode household income
egen household_income_min = min(household_income)
egen household_income_max = max(household_income)
gen household_income_rescaled = (household_income - household_income_min) / (household_income_max - household_income_min)

**recode registered to vote > proxy for citizenship
recode registration (2=0) (999=0)

**recode educ
egen education_min = min(education)
egen education_max = max(education)
gen education_rescaled = (education - education_min) / (education_max - education_min)

**create catholic
gen catholic = 0
replace catholic = 1 if religion == 2

**no marriage status

**generate year
gen year = 2022

**no zipcode > census region?
**i.census

**foreign_born rescale
recode foreign_born (2=0)
rename foreign_born US_born

**recode language
gen spanish_in_home = 0
replace spanish_in_home = 1 if language == 1

**build wall at the border
recode wall (2=0) (999=0.5)

**path to citizenship
recode path_to_citizenship (2=0) (999=0.5)

**is hispanic
gen ishispanic = 0
replace ishispanic = 1 if hispanic > 1
replace ishispanic = 1 if attritor == 1
**regressions
**one for mixed kids, one for non mixed
**one to black one to white

svyset [pweight=weight]

**code for missingness
*svy: regress white_attritor racial_resentment_rescaled pid7_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home if ishispanic == 1

gen pid7_missing = 0
replace pid7_missing = 1 if pid7 == .
replace pid7_rescaled = 0 if pid7_missing == 1
replace pid7 = 4 if pid7_missing == 1

*no one missing
gen generation_missing = 0
replace generation_missing = 1 if generation == .

gen income_missing = 0
replace income_missing = 1 if household_income == .
replace household_income_rescaled = 0 if income_missing == 1

*no one missing
gen US_born_missing = 0
replace US_born_missing = 1 if US_born == .

*no one missing
gen education_missing = 0
replace education_missing = 1 if education == .

*no one missing
gen spanish_speak_missing = 0
replace spanish_speak_missing = 1 if spanish_in_home == .

gen racial_resentment_missing = 0
replace racial_resentment_missing = 1 if racial_resentment == .
replace racial_resentment_rescaled = 0 if racial_resentment_missing == 1

gen ideo5_missing = 0
replace ideo5_missing = 1 if ideo5 == .
**recoded ideo5 on 1/23 so not sure = 0 instead of 1
replace ideo5_missing = 1 if ideo5 == 6
recode ideo5 (999=3)
replace ideo5 = 3 if ideo5_missing == 1

*****thesis models and code here

***writing paper
***power analysis

**power vs hispancis for white attritors
svy: mean racial_resentment_rescaled if white_attritor == 1
**sd = se*sqr(n)
**sd=0.0093656*sqr884 = 0.2784593
svy: mean racial_resentment_rescaled if attritor == 0 & ishispanic == 1
**sd = se*sqr(n)
**sd = 0.0045119*sqr10563 = 0.463717
power twomeans 0.5313099 0.4978835, sd1(0.2784593) sd2(0.463717) n1(884) n2(10653) graph

power twomeans 0.5313099 0.4978835, sd1(0.2784593) sd2(0.463717) n1(884) n2(10653)
**power vs whites
power twomeans 0.4978835, power(0.9) n(500 2000 3000 5000 7000 9000 11000) sd(0.463717) graph
**difference we can detect if we double the attritors is like 0.065, difference if we do total sample size is 0.03
power twomeans 0.4978835, power(0.8) n(500 2000 3000 5000 7000 9000 11000) sd(0.463717) graph
***descriptive statistics white attritors
*svy: regress white_attritor racial_resentment_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home if ishispanic == 1

svy: mean racial_resentment_rescaled if white_attritor == 1
svy: mean racial_resentment_rescaled if attritor == 0 & ishispanic == 1

svy: mean pid7 if white_attritor == 1
svy: mean pid7 if attritor == 0 & ishispanic == 1

svy: mean generation if white_attritor == 1
svy: mean generation if attritor == 0 & ishispanic == 1

svy: mean household_income if white_attritor == 1
svy: mean household_income if attritor == 0 & ishispanic == 1

svy: tab US_born if white_attritor == 1
svy: tab US_born if attritor == 0 & ishispanic == 1

svy: mean education if white_attritor == 1
svy: mean education if attritor == 0 & ishispanic == 1

svy: tab catholic if white_attritor == 1
svy: tab catholic if attritor == 0 & ishispanic == 1

svy: tab spanish_in_home if white_attritor == 1
svy: tab spanish_in_home if attritor == 0 & ishispanic == 1

**descriptive statistics black attritors
svy: mean racial_resentment_rescaled if black_attritor == 1
svy: mean racial_resentment_rescaled if attritor == 0 & ishispanic == 1

svy: mean pid7 if black_attritor == 1
svy: mean pid7 if attritor == 0 & ishispanic == 1

svy: mean generation if black_attritor == 1
svy: mean generation if attritor == 0 & ishispanic == 1

svy: mean household_income if black_attritor == 1
svy: mean household_income_rescaled if attritor == 0 & ishispanic == 1

svy: mean US_born if black_attritor == 1
svy: mean US_born if attritor == 0 & ishispanic == 1

svy: mean education if black_attritor == 1
svy: mean education if attritor == 0 & ishispanic == 1

svy: mean catholic if black_attritor == 1
svy: mean catholic if attritor == 0 & ishispanic == 1

svy: mean spanish_in_home if black_attritor == 1
svy: mean spanish_in_home if attritor == 0 & ishispanic == 1

***model results white attritors
***model a
svy: regress white_attritor racial_resentment_rescaled if ishispanic == 1 & black_attritor == 0
outreg2 using "table4AAA.doc"

***model b.i
svy: regress white_attritor racial_resentment_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing if ishispanic == 1 & black_attritor == 0
outreg2 using "tablebbbi.doc"

***model b.ii
svy: regress white_attritor racial_resentment_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & black_attritor == 0
outreg2 using "table4bbbii.doc"

***model c
svy: regress white_attritor racial_dating_rescaled if ishispanic == 1 & black_attritor == 0
outreg2 using "table4ccciii.doc"

***model d
svy: regress white_attritor racial_dating_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & black_attritor == 0
outreg2 using "table4ddD.doc"

**model results black attritors
***model e 
svy: regress black_attritor racial_resentment_rescaled if ishispanic == 1 & white_attritor == 0
outreg2 using "table4x.doc"

***model f.i (f)
svy: regress black_attritor racial_resentment_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing if ishispanic == 1 & white_attritor == 0
outreg2 using "table4AAA.doc"

***model f.ii (f)
svy: regress black_attritor racial_resentment_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & white_attritor == 0
outreg2 using "table4BB.doc"

***model g
svy: regress black_attritor racial_dating_rescaled if ishispanic == 1 & white_attritor == 0
outreg2 using "table4GG.doc"

***model h
svy: regress black_attritor racial_dating_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & white_attritor == 0
outreg2 using "table4DD.doc"


**robustness checks - probit
***model results white attritors
***model a
svy: probit white_attritor racial_resentment_rescaled if ishispanic == 1 & black_attritor == 0
outreg2 using "table4AAAp.doc"

***model b.i
svy: probit white_attritor racial_resentment_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing if ishispanic == 1 & black_attritor == 0
outreg2 using "tablebbbip.doc"

***model b.ii
svy: probit white_attritor racial_resentment_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & black_attritor == 0
outreg2 using "table4bbbiip.doc"

***model c
svy: probit white_attritor racial_dating_rescaled if ishispanic == 1 & black_attritor == 0
outreg2 using "table4ccciiip.doc"

***model d
svy: probit white_attritor racial_dating_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & black_attritor == 0
outreg2 using "table4ddDp.doc"

**model results black attritors
***model e 
svy: probit black_attritor racial_resentment_rescaled if ishispanic == 1 & white_attritor == 0
outreg2 using "table4xxp.doc"

***model f.i (f)
svy: probit black_attritor racial_resentment_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing if ishispanic == 1 & white_attritor == 0
*outreg2 using "table4AAAp.doc"
outreg2 using "table4xxp.doc"

***model f.ii (f)
svy: probit black_attritor racial_resentment_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & white_attritor == 0
*outreg2 using "table4BBp.doc"
outreg2 using "table4xxp.doc"

***model g
svy: probit black_attritor racial_dating_rescaled if ishispanic == 1 & white_attritor == 0
*outreg2 using "table4GGp.doc"
outreg2 using "table4xxp.doc"

***model h
svy: probit black_attritor racial_dating_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & white_attritor == 0
*outreg2 using "table4DDp.doc"
outreg2 using "table4xxp.doc"

***
***
***robustness checks: measure of attrition
***model results white attritors
***model a
svy: regress full_attritor_white racial_resentment_rescaled if ishispanic == 1 & black_attritor == 0
outreg2 using "tableAattrition.doc"

***model b.i
svy: regress full_attritor_white racial_resentment_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing if ishispanic == 1 & black_attritor == 0
outreg2 using "tableAattrition.doc"

***model b.ii
svy: regress full_attritor_white racial_resentment_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & black_attritor == 0
outreg2 using "tableAattrition.doc"

***model c
svy: regress full_attritor_white racial_dating_rescaled if ishispanic == 1 & black_attritor == 0
outreg2 using "tableAattrition.doc"

***model d
svy: regress full_attritor_white racial_dating_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & black_attritor == 0
outreg2 using "tableAattrition.doc"

**model results black attritors
***model e 
svy: regress full_attritor_black racial_resentment_rescaled if ishispanic == 1 & white_attritor == 0
outreg2 using "tableBattrition.doc"

***model f.i (f)
svy: regress full_attritor_black racial_resentment_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing if ishispanic == 1 & white_attritor == 0
outreg2 using "tableBattrition.doc"

***model f.ii (f)
svy: regress full_attritor_black racial_resentment_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & white_attritor == 0
outreg2 using "tableBattrition.doc"

***model g
svy: regress full_attritor_black racial_dating_rescaled if ishispanic == 1 & white_attritor == 0
outreg2 using "tableBattrition.doc"

***model h
svy: regress full_attritor_black racial_dating_rescaled pid7_rescaled ideo5_rescaled i.gender monthyear generation household_income_rescaled US_born education_rescaled catholic spanish_in_home income_missing pid7_missing ideo5_missing if ishispanic == 1 & white_attritor == 0
outreg2 using "tableBattrition.doc"

**power vs whites
power twomeans 0.4978835, power(0.9) n(2000 3000 5000 7000 9000 11000) sd(0.463717) graph
**difference we can detect if we double the attritors is like 0.065, difference if we do total sample size is 0.03


**maybe democrats and republicans are primed to perceive and analyze hierarchy more so this gives a clearer racial frame for resentment to be translated into, whereas independents have less knowledge of how to translate the racial binary 
**proof - independent attritors are almost perfectly distributed across the racial resentment scale, while partisans are more concentrated
